/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.factory.web.backing;

import com.factory.web.json.Problem;
import com.factory.web.dto.UserTaskDTO;
import com.factory.web.service.FactoryService;
import com.factory.web.service.problems.ProblemEnum;
import com.factory.web.service.FactoryServiceInterface;
import java.io.IOException;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
 *
 * @author milos
 */
@Component("factoryBackingBean")
@Scope("session")
public class FactoryBackingBean {
    @Autowired
    FactoryServiceInterface factoryService;

    public String sort() throws IOException {
        return "uploadFile";
//        FacesContext.getCurrentInstance().getExternalContext().redirect("uploadFile.xhtml");
    }

    public void downloadResult(UserTaskDTO userTaskDTO) throws IOException {
        factoryService.getResultFile(userTaskDTO.getInputId());
    }

    public List<UserTaskDTO> getUserTasks() {
        return factoryService.getUserTasks();
    }

    public String chosenSort() {
        factoryService.setProblem(new Problem(ProblemEnum.SORT));
        return "uploadFile";
    }

    public String chosenFibb() {
        factoryService.setProblem(new Problem(ProblemEnum.FIBB));
        return "fibbInput";
    }

    public String chosenSpanningTree() {
        factoryService.setProblem(new Problem(ProblemEnum.SPANN_TREE));
        return "spannTreeInput";
    }

    public String chosenShortestpath() {
        factoryService.setProblem(new Problem(ProblemEnum.SHORTEST_PATH));
        return "uploadFile";
    }

    public String chosenTopologicalOrder() {
        factoryService.setProblem(new Problem(ProblemEnum.TOPOLOGICAL_ORDER));
        return "uploadFile";
    }

    public String chosenEratosthenes() {
        factoryService.setProblem(new Problem(ProblemEnum.ERATOSTHENES));
        return "eratosthenesInput";
    }

    public String chosenLevehshtein() {
//        factoryService.setProblem(new Problem(ProblemEnum.LEVENSHTEIN));
        return "levenshteinInput";
    }

    public String chosenTSP() {
        factoryService.setProblem(new Problem(ProblemEnum.TSP));
        return "uploadFile";
    }
}
